package com.skivingcloud.admin.sys.controller;


import java.util.HashMap;
import java.util.Map;

import com.skivingcloud.admin.sys.entity.SysLog;
import com.skivingcloud.admin.sys.entity.User;
import com.skivingcloud.admin.sys.service.ISysLogService;
import com.skivingcloud.admin.utils.UserUtil;
import com.skivingcloud.common.utils.PageUtils;
import com.skivingcloud.common.utils.R;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

/**
 * <p>
 * 系统日志 前端控制器
 * </p>
 *
 * @author skivingcloud
 * @since 2022-01-28
 */
@RestController
@RequestMapping("/sys/log")
public class SysLogController {
	
	private static Logger log = LoggerFactory.getLogger(SysLogController.class);

	@Autowired
	private ISysLogService sysLogService;
	
	/**
	 * 日志查询
	 * 
	 * @param page
	 * @param limit
	 * @param staff_name
	 * @param username
	 * @param user_ip
	 * @param oper_time_start
	 * @param oper_time_end
	 * @return
	 */
	@RequestMapping(value = "/list", method = RequestMethod.GET)
	@ResponseBody
	public R list(String page, String limit, String staff_name, String username, String user_ip, String oper_time_start,
			String oper_time_end) {
		Map<String, Object> params = new HashMap<String, Object>();
		params.put("page", page);
		params.put("limit", limit);
		params.put("staff_name", staff_name);
		params.put("username", username);
		params.put("user_ip", user_ip);
		params.put("oper_time_start", oper_time_start);
		params.put("oper_time_end", oper_time_end);
		PageUtils pages = sysLogService.queryPage(params);
		return new R().put("page", pages);
	}

	/**
	 * 记录日志
	 * 
	 * @param sysLog
	 */
	@RequestMapping(value = "/save", method = RequestMethod.POST)
	public void save(@RequestBody SysLog sysLog) {

		User user = UserUtil.getUser();
		sysLogService.insertLog(sysLog);

	}
}
